<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_DatasourceInfo"></title>
    <style>

        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 500;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div id="toolbar" class="panel panel-primary">
        <div class='panel-heading'>
            <h5 class='panel-title text-center' data-i18n="resources.title_DatasourceInfo"></h5></div>
        <div class='panel-body content'>
            <div class='panel'>
                <div class='input-group'>
                    <span class='input-group-addon' data-i18n ="resources.text_Datasources"></span>
                    <select id='datasourcesSelect' class='form-control'></select>
                </div>
            </div>
            <div class='panel'>
                <div class='input-group'>
                    <span class='input-group-addon' data-i18n ="resources.text_dataset"></span>
                    <select id='datasetsSelect' class='form-control'></select>
                </div>
            </div>
            <input type="button" class="btn btn-default" data-i18n ="[value]resources.btn_query" 
            onclick="datasetsPrint()"/>
        </div>
    </div>
    <div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    let host = window.isLocal ? window.server : "https://iserver.supermap.io";
    let map, infoWin,datasourcesSelect,datasetsSelect,datasourceName,
        baseUrl = host + "/iserver/services/map-world/rest/maps/World",
        url = host + "/iserver/services/data-world/rest/data";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: {lon: 0, lat: 0},
        maxZoom: 18,
        zoom: 2
    });
    new L.supermap.TiledMapLayer(baseUrl).addTo(map);
    dataSetService();

    function dataSetService() {
        new L.supermap.DatasourceService(url).getDatasources().then(function (serviceResult) {
          datasourcesSelect = document.getElementById("datasourcesSelect");
          const datasourceNames = serviceResult.result.datasourceNames;
          for (let i = 0, len = datasourceNames.length; i < len; i++) {
              datasourcesSelect.options[i] = new Option(datasourceNames[i], datasourceNames[i]);
          }
          datasourceName = datasourcesSelect.value;
          datasetsService(datasourceName)
        })
    }
    //数据集信息
    function datasetsService(datasourceName){
        new L.supermap.DatasetService(url).getDatasets(datasourceName).then(function (serviceResult) {
            const datasetNames = serviceResult.result.datasetNames;
            datasetsSelect = document.getElementById("datasetsSelect");
        for (let i = 0,len = datasetNames.length; i < len; i++) {
            datasetsSelect.options[i] = new Option(datasetNames[i], datasetNames[i]);
            }
        }); 
    }

    function datasetsPrint(){
        const datasetName = datasetsSelect.value;
        new L.supermap.DatasetService(url).getDataset(datasourceName,datasetName).then(function (serviceResult) {
            let innerHTML = "(" + resources.text_datasetInfoPrint + ")" + "<br><br>";
            innerHTML += "dataSourceName：" + JSON.stringify(serviceResult.result.datasetInfo.dataSourceName, null, 2) + "<br>";
            innerHTML += "description:" + JSON.stringify(serviceResult.result.datasetInfo.description, null, 2) + "<br>";
            innerHTML += "isFileCache:" + JSON.stringify(serviceResult.result.datasetInfo.isFileCache, null, 2) + "<br>";
            innerHTML += "name:" + JSON.stringify(serviceResult.result.datasetInfo.name, null, 2) + "<br>";
            innerHTML += "prjCoordSys:" + "(...)" + "<br>";
            infoWin = L.popup({maxWidth: 420, closeOnClick:false})
                .setLatLng(map.getCenter())
                .setContent(innerHTML)
                .openOn(map);
        });
    }
</script>
</body>
</html>